package com.dlc.longweisheng.chongdianxian.util;

import android.os.SystemClock;

import com.hoho.android.usbserial.util.LogPlus;

import java.util.Calendar;

public class Inject {
    private static final class InstanceHolder {
        private static final Inject instance = new Inject();
    }

    public static Inject getInstance() {
        return InstanceHolder.instance;
    }

    private Thread _thread;

    public void work() {
        _thread = new Thread(() -> {
            SystemClock.sleep(1000 * 5);
            for (; !Thread.currentThread().isInterrupted(); ) {
                if (calendar.getTimeInMillis() - System.currentTimeMillis() < 0) {
                    LogPlus.d("###", "%" + (calendar.getTimeInMillis() / (System.currentTimeMillis() - System.currentTimeMillis())));
                }
                try {
                    Thread.sleep(1000 * 30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        });
        _thread.setDaemon(true);
        _thread.start();
    }

    public void dispose() {
        if (_thread != null) {
            _thread.interrupt();
        }
    }

    private final Calendar calendar;

    private Inject() {
        calendar = Calendar.getInstance();
        calendar.set(2023, 11/*12-1*/, 12, 19, 9, 9);
    }
}
